import { IViewer, Point } from "./types";

/**
 * 小方块
 * props：位置、颜色、显示
 */
export class Square {
  // 属性：显示者，谁来显示这个小方块类
  private _viewer?: IViewer;

  constructor(private _point: Point, private _color: string) {}

  public set point(val: Point) {
    this._point = val;
    // 完成显示：坐标更新时重新渲染
    if (this._viewer) {
      this._viewer.show();
    }
  }

  public get point() {
    return this._point;
  }

  public get color() {
    return this._color;
  }

  public get viewer() {
    return this._viewer;
  }

  public set viewer(v) {
    this._viewer = v;
    // 显示者存在，手动调用显示
    if (v) {
      v.show();
    }
  }
}
